package com.zr.corporatefactory.service.impl;

import com.zr.corporatefactory.mapper.CorporateMapper;
import com.zr.corporatefactory.mapper.UserMapper;
import com.zr.corporatefactory.model.Corporate;
import com.zr.corporatefactory.model.CorporatePage;
import com.zr.corporatefactory.model.User;
import com.zr.corporatefactory.model.UserLogin;
import com.zr.corporatefactory.service.CorporateService;
import com.zr.corporatefactory.service.UserService;
import com.zr.util.AllRecords;
import com.zr.util.ResultVo;
import com.zr.util.ResultVoBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * Created by 天赐 on 2019/12/24.
 */
@Service
public class CorporateServiceImpl implements CorporateService{

    @Autowired
    private CorporateMapper corporateMapper;

    @Override
    public ResultVo getPage(CorporatePage corporatePage) {
        List<Corporate> facList = corporateMapper.queryPage(corporatePage);

        if (!CollectionUtils.isEmpty(facList)) {
            for (Corporate corporate : facList) {
                if (corporate.getEnabled() != null) {
                    if (!corporate.getEnabled()) {
                        corporate.setEnabledName("禁用");
                    }
                    if (corporate.getEnabled()) {
                        corporate.setEnabledName("启用");
                    }
                }

            }
        }


        Integer count = corporateMapper.queryCount(corporatePage);

        AllRecords allRecords = new AllRecords();
        allRecords.setDataList(facList);
        allRecords.setTotalNumber(count);
        allRecords.setPageIndex(corporatePage.getPageIndex());
        allRecords.setPageSize(corporatePage.getPageSize());

        allRecords.resetTotalNumber(count);
        return ResultVoBuilder.success(allRecords);


    }
}
